<template>
  <view class="bg">
    <view v-if="empInfo.verified" class="page-wrapper">
      <template v-if="contractlist.length > 0">
        <view
          v-for="(item, index) in contractlist"
          :key="index"
          class="contract-wrapper"
          @click="signContract(item)"
        >
          <view class="wrap-left">
            <img
              :src="
                item.status === 0
                  ? '/contract/img/pdf.png'
                  : '/contract/img/wod.png'
              "
              alt
            />
            <span>{{ item.contractName }}</span>
          </view>
          <view class="wrap-right">
            <span
              :class="
                item.status === -1
                  ? 'outdate'
                  : item.status === 0
                  ? 'contract-status2'
                  : 'contract-status'
              "
            >
              {{
              item.status === 0
              ? "待我签署"
              : item.status === 1
              ? "签署完成"
              : "已过期"
              }}
            </span>
            <span class="contract-time" v-if="item.contractPublishDate">
              {{
              item.contractPublishDate | fullTime(item.contractPublishDate)
              }}
            </span>
            <span v-else>--</span>
          </view>
        </view>
      </template>
      <view
        v-else
        style="width: 100vw; height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: cneter;"
      >
        <img
          style="width: 200px; height: 200px; margin: 0 auto;"
          src="/contract/img/meiyou_jilu.png"
        />
        <view style="margin-top: 20px; color: #999; text-align: center;">暂无合同记录</view>
      </view>
    </view>
    <view v-if="!empInfo.verified" class="tip-wrapper">
      <view class="tippic">
        <img src="/contract/img/hetongrenzheng.png" alt />
      </view>
      <p class="tips">为确保电子合同的有效性，需要证实签署方身份真实，请在签署合同前先完成实名认证</p>
      <button class="btn btn-auth" @click="goAuthentication">立即认证</button>
    </view>
  </view>
</template>
<script>
import { fullTime } from "@/utils/tools.js";
import { myContractList } from "@/services/contract";
import { mapState } from "vuex";
export default {
  filters: {
    fullTime: fullTime
  },
  data() {
    return {
      contractlist: [],
      empInfo: {}
    };
  },
  computed: {
    ...mapState(["site"])
  },

  onShow() {
    this.empInfo = this.site;
    // var that = this;
    if (this.empInfo.verified) {
      this.getContractList();
    }
    // uni.startPullDownRefresh({
    //   success: function(res) {
    //     if (that.empInfo.verified) {
    //       that.getContractList();
    //     }
    //   }
    // }); // 这里表示当进入页面的时候就开始执行下拉刷新动画
  },
  onPullDownRefresh() {
    // 监听下拉刷新动作的执行方法，每次手动下拉刷新都会执行一次
    this.empInfo = this.site;
    if (this.empInfo.verified) {
      myContractList().then(res => {
        this.contractlist = res;
        uni.stopPullDownRefresh();
      });
    }
  },
  methods: {
    getContractList() {
      myContractList().then(res => {
        this.contractlist = res;
      });
    },
    signContract(item) {
      console.log("item", item);
      if (item.status === 0) {
        uni.navigateTo({
          url:
            "/contract/preview?contractId=" +
            item.contractId +
            "&status=" +
            item.status
        });
      } else {
        if (item.contractAppShow === false) {
          uni.navigateTo({
            url: "/contract/succeed"
          });
        } else {
          uni.navigateTo({
            url:
              "/contract/preview?contractId=" +
              item.contractId +
              "&status=" +
              item.status
          });
        }
      }
    },
    goAuthentication() {
      uni.navigateTo({
        url: "/authorize/realname"
      });
    }
  }
};
</script>
<style lang="scss">
.bg {
  width: 100%;
  overflow-x: hidden;
  min-height: 100vh;
  background: rgba(250, 251, 251, 1);
}
.page-wrapper {
  width: 100%;
  padding: 12px 10px;
  background: rgba(250, 251, 251, 1);
  .contract-wrapper {
    height: 68px;
    background: rgba(255, 255, 255, 1);
    box-shadow: 0px 0px 6px 0px rgba(0, 0, 0, 0.12);
    border-radius: 10px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .wrap-left {
    display: flex;
    align-items: center;
    padding-left: 12px;
    img {
      width: 36px;
      height: 36px;
      background: rgba(216, 216, 216, 0);
      flex-shrink: 0;
    }
    span {
      font-size: 15px;
      font-weight: 400;
      color: rgba(51, 51, 51, 1);
      line-height: 21px;
      padding-left: 12px;
      height: 42px;
      width: calc(100vw - 160px);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
  .wrap-right {
    padding-right: 12px;
    width: 74px;
    display: flex;
    flex-direction: column;
    .contract-status {
      font-size: 14px;
      font-weight: 400;
      color: rgba(51, 51, 51, 1);
      line-height: 20px;
    }
    .contract-status2 {
      font-size: 14px;
      font-weight: 400;
      color: $theme;
      line-height: 20px;
    }
    .outdate {
      font-size: 14px;
      font-weight: 400;
      color: #c0c0c0;
      line-height: 20px;
    }
    .contract-time {
      font-size: 12px;
      font-weight: 400;
      color: rgba(192, 192, 192, 1);
      line-height: 17px;
    }
  }
}
</style>
